package fr.java_freelance.tryspock;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import fr.java_freelance.tryspock.data.CalendarDao;
import fr.java_freelance.tryspock.domain.SpockInfo;

@Path("spock")
@Component
public class SpockResource {
  private DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
  private CalendarDao calendarDao;

  @Autowired
  public SpockResource(
      @Qualifier("calendarDaoStatic") CalendarDao calendarDao) {
    this.calendarDao = calendarDao;
  }

  @GET
  @Produces({ MediaType.APPLICATION_XML })
  @Path("/number/{day}")
  public SpockInfo findCalendarByDay(
      @PathParam("day") String day) {
    SpockInfo spockInfo = calendarDao
        .getInfosByDay(day);
    return spockInfo;
  }

}
